<template>
  <div>
    <a-card :title="t['对接审核']" class="mb-4">
      <div class="flex gap-2 items-center w-full">
        <a-button @click="reload">{{ t["刷新"] }}</a-button>
        <div class="flex gap-2 items-center text-nowrap">
          <span>{{ t["状态"] }}</span>
          <div class="w-[200px]">
            <a-select
              allowClear
              v-model="query.status"
              @change="emit('search')"
              :options="translateOptions(isOptions)"
            />
          </div>
          <a-input-search @search="emit('search')" v-model="query.uid"></a-input-search>
        </div>
      </div>
    </a-card>
    <a-table
      :columns="translateColumns(columns)"
      :pagination="{
        current: query.pageNum,
        total: query.total,
        pageSize: query.pageSize
      }"
      :data="table.data"
      @page-size-change="pageSizeChange"
      @page-change="pageChange"
    >
      <template #actions="{ record }">
        <a-button v-if="record.status === '1'" @click="active(record)">{{ t["审核"] }}</a-button>
      </template>
      <template #status="{ record }">
        <a-tag>{{ t[record.status === "0" ? "是" : "否"] }}</a-tag>
      </template>
    </a-table>
  </div>
</template>

<script setup lang="ts">
import { auditActive } from "@/api/service/audit/audit";

import { IQuery, TableConfig } from "@/interface/IAxios";
import { isOptions } from "../../menu/data";
import columns from "../columns";
const t = translate("公共模块");
const emit = defineEmits(["reload", "search"]);
const props = defineProps<{
  query: IQuery;
  table: TableConfig<IAudit>;
}>();

const active = async (config: IAudit) => {
  await auditActive({
    extendParams: config.extendParams,
    uid: config.uid
  });
  emit("reload");
};
const reload = () => {
  emit("reload");
};

const pageChange = (page: number) => {
  props.query.pageNum = page;
  emit("reload");
};
const pageSizeChange = (pageSize: number) => {
  props.query.pageSize = pageSize;
  emit("reload");
};
</script>

<style lang="scss" scoped></style>
